package org.handsome.jvm;

/**
 * 简单的GC例子
 */
public class LocalVarGCDemo {

    /**
     * 本地变量GC1
     */
    public void localVarGC1(){
        //分配6M的堆空间
        byte[] a = new byte[6 * 1024 * 1024];
        System.gc();
    }

    public void localVarGC2(){
        byte[] a = new byte[6 * 1024 * 1024];
        a = null;
        System.gc();
    }

    public void localVarGC3(){
        {
            byte[] a = new byte[6 * 1024 * 1024];
        }
        System.gc();
    }

    public void localVarGC4(){
        {
            byte[] a = new byte[6 * 1024 * 1024];
        }
        int c = 10;
        System.gc();
    }

    public void localVarGC5(){
        this.localVarGC1();
        System.gc();
    }

    public static void main(String[] args) {
        LocalVarGCDemo demo = new LocalVarGCDemo();
//        demo.localVarGC1();
//        demo.localVarGC2();
//        demo.localVarGC3();
        demo.localVarGC4();
//        demo.localVarGC5();

    }
}



